package com.bw.spring.security.controller;


import com.bw.spring.security.entity.User;
import com.bw.spring.security.exception.UserException;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {



    @RequestMapping(value = "/list/{userName}/{password}",method= RequestMethod.GET)
    public  List<User> getUser(@PathVariable String userName, @PathVariable String password){

        List<User> list = new ArrayList<User>();
        list.add(new User());
        list.add(new User());
        list.add(new User());
        return list;
    }

    @ApiOperation(value = "查询用户列表")
    @RequestMapping(value = "/getUser",method= RequestMethod.GET)
    public  List<User> getUser(@Valid User user){

        throw new UserException("1","用户信息异常");

//        if (result.hasErrors()){
//            result.getAllErrors().forEach(e->{
//                System.out.println(e);
//            });
//        }
//        List<User> list = new ArrayList<>();
//        list.add(new User());
//        list.add(new User());
//        list.add(new User());
//        return list;
    }


    @GetMapping(value = "/userById")
    public User getUserById(@RequestParam  String id){
        return new User();


    }

    @RequestMapping(method= RequestMethod.POST)
    public User addUser(){
        return new User();
    }
    @RequestMapping(method= RequestMethod.PUT)
    public User updateUser(){
        return new User();
    }
    @RequestMapping(method= RequestMethod.DELETE)
    public User delUser(){
        return new User();
    }
}
